//
//  OneCompanyVC.m
//  HNJYB
//
//  Created by panshen on 2017/10/25.
//  Copyright © 2017年 Mag1cPanda. All rights reserved.
//

#import "OneCompanyVC.h"
#import "BXBAView.h"
#import "OneTipsViewController.h"

@interface OneCompanyVC ()
{
    BXBAView *bfView;
    
    NSString *dutyType;
}
@end

@implementation OneCompanyVC

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.title = @"保险理赔";
    
    bfView = [[NSBundle mainBundle] loadNibNamed:@"BXBAView" owner:nil options:nil][0];
    bfView.frame = CGRectMake(0, 0, ScreenWidth, 370);
    bfView.listView.dataArr = _comArr;
    bfView.title.text = @"保险信息";
    
    NSDictionary *tmpDic = GlobleInstance.casecarlist[0];
    bfView.name.text = tmpDic[@"carownname"];
    bfView.carno.text = tmpDic[@"casecarno"];
    bfView.phone.text = tmpDic[@"carownphone"];
    if ([tmpDic[@"dutytype"] isEqualToString:@"0"]) {
        bfView.qzBtn.selected = YES;
    }
    
    if ([tmpDic[@"dutytype"] isEqualToString:@"1"]) {
        bfView.wzBtn.selected = YES;
    }
    
    
    NSString *ownins = _ownDic[@"inscomname"];
    if (ownins.length > 0) {
        [bfView.jqxBtn setTitle:ownins forState:0];
        bfView.inscomcode = _ownDic[@"inscomcode"];
        bfView.inscomname = _ownDic[@"inscomname"];
    }
    
    [self.view addSubview:bfView];
    
    
    
    UIButton *nextBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    nextBtn.frame = CGRectMake(10, 400, ScreenWidth-20, 50);
    [nextBtn setTitle:@"提交" forState:0];
    [nextBtn setTitleColor:[UIColor whiteColor] forState:0];
    nextBtn.backgroundColor = HNBlue;
    nextBtn.titleLabel.font = HNFont(16);
    [nextBtn addTarget:self action:@selector(nextBtnClicked) forControlEvents:1 << 6];
    nextBtn.layer.cornerRadius = 5;
    [self.view addSubview:nextBtn];
    
    
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


-(void)nextBtnClicked
{
    
    if (!bfView.inscomcode) {
        [Util showHudWithView:self.view message:@"请选择交强险承保公司" hideAfterDelay:1.0];
        return;
    }
    
    
    NSString *imagelon = [NSString stringWithFormat:@"%f", GlobleInstance.imagelon];
    NSString *imagelat = [NSString stringWithFormat:@"%f", GlobleInstance.imagelat];
    
    NSMutableDictionary *bean = [NSMutableDictionary dictionary];
    [bean setValue:GlobleInstance.appcaseno forKey:@"appcaseno"];
    [bean setValue:GlobleInstance.casecarno forKey:@"casecarno"];
    [bean setValue:GlobleInstance.casetelephone forKey:@"casetelephone"];
    [bean setValue:imagelon forKey:@"caselon"];
    [bean setValue:imagelat forKey:@"caselat"];
    [bean setValue:GlobleInstance.imageaddress forKey:@"caseaddress"];
    
    NSString *currentDateStr = [self getCurrentTime];
    [bean setValue:currentDateStr forKey:@"casedate"];
    
    [bean setValue:bfView.inscomcode forKey:@"inscomcode"];
    
    [bean setValue:@"0" forKey:@"reportway"];
    
    [bean setValue:GlobleInstance.areaid forKey:@"areaid"];
    [bean setValue:_reportway forKey:@"type"];
    [bean setValue:GlobleInstance.userflag forKey:@"userflag"];
    [bean setValue:GlobleInstance.token forKey:@"token"];
    
    NSArray *tmpArr = GlobleInstance.casecarlist;
    NSDictionary *tmpDic = tmpArr[0];
    NSMutableDictionary *bfInfo = [NSMutableDictionary dictionaryWithDictionary:tmpDic];
    [bfInfo setValue:bfView.inscomname forKey:@"inscomname"];
    [bfInfo setValue:bfView.inscomcode forKey:@"inscomcode"];
    [bfInfo setValue:bfView.bussisinscompany forKey:@"bussisinscompany"];
    [bfInfo setValue:bfView.bussisinscomcode forKey:@"bussisinscomcode"];
    tmpArr = @[bfInfo];
    
    [bean setValue:[Util objectToJson:tmpArr] forKey:@"casecarlist"];
    
    MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:self.view animated:true];
    
    [LSHttpManager requestUrl:HNServiceURL serviceName:@"jjappsubmitCaseInforInscompany" parameters:bean complete:^(id result, ResultType resultType) {
        
        [hud hideAnimated:YES];
        if (result) {
            NSLog(@"%@", JsonResult);
        }
        
        if ([result[@"restate"] isEqualToString:@"1"]) {
            OneTipsViewController *vc = [OneTipsViewController new];
            [self.navigationController pushViewController:vc animated:YES];
        }
        
        else {
            [Util showHudWithView:self.view message:result[@"redes"] hideAfterDelay:1.0];
        }
        
    }];
}

-(NSString *)getCurrentTime
{
    //实例化一个NSDateFormatter对象
    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
    //设定时间格式,这里可以设置成自己需要的格式
    [dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
    //用[NSDate date]可以获取系统当前时间
    NSString *currentDateStr = [dateFormatter stringFromDate:[NSDate date]];
    //输出格式为：2010-10-27 10:22:13
    NSLog(@"%@", currentDateStr);
    
    return currentDateStr;
}

-(void)backAction
{
    [self.navigationController popViewControllerAnimated:YES];
}



@end
